function [outdat] = rt_rawdat_query(siteID,t_interval)
%SELECT  FROM  WHERE 
try
    sqlQuery = {'CalculatedValue.DensityCalculated,CalculatedValue.DOCalculated,CalculatedValue.DOSaturationCalculated,RawValue.RawValueID,RawValue.SiteID,RawValue.PostedUTCDatetime,RawValue.PressureQuantity,RawValue.TemperatureQuantity,RawValue.ConductivityQuantity,RawValue.SalinityQuantity,Site.SiteID,Site.SiteName,Site.SiteDescription,Site.SiteTypeID,Site.LatitudeDecimal,Site.LongitudeDecimal,Site.SiteMLLWDecimal',...
                'FROM CalculatedValue, RawValue, Site',...                
                ['WHERE RawValue.SiteID =''' siteID...
                ''' AND RawValue.PostedUTCDatetime >= ''' datestr(t_interval(1),23)...
                ''' AND RawValue.PostedUTCDatetime <= ''' datestr(t_interval(2),23)...
                ''' AND CalculatedValue.RawValueID = RawValue.RawValueID '''...
                ''' AND Site.SiteID = RawValue.SiteID'''],...
                'ORDER BY PostedUTCDatetime;'};
               
    conn   = database('Mooring_COTS_Dev', '', '');
    dbmeta = get(dmd(conn));
    disp(['User: ' dbmeta.UserName])
    execstr = strcat(sqlQuery{1}, ' ', sqlQuery{2}, ' ', sqlQuery{3}, ' ', sqlQuery{4})
    curs   = exec(conn, [sqlQuery{1} ' ' sqlQuery{2} ' ' sqlQuery{3} ' ' sqlQuery{4}]);
    setdbprefs('DataReturnFormat','cellarray')
    curs = fetch(curs);
    close(conn)
    outdat = curs.Data
    h = msgbox('Data Extracted...','Success');
catch ME
    h = errordlg('Error Extracting Data...','Error');
end

conn   = database('Mooring_COTS_Dev', '', '');
dbmeta = dmd(conn);